Inverse of Log CDF of Normal Distribution · Issue #13923 · scipy/scipy · GitHub 您所在的位置:网站首页 scipy normal distribution Inverse of Log CDF of Normal Distribution · Issue #13923 · scipy/scipy · GitHub

Inverse of Log CDF of Normal Distribution · Issue #13923 · scipy/scipy · GitHub

#Inverse of Log CDF of Normal Distribution · Issue #13923 · scipy/scipy · GitHub| 来源: 网络整理| 查看: 265

Is your feature request related to a problem? Please describe. We were interested in calculating z-scores associated to log p-values in the situation where log(p) can be very small. The naive solution of applying scipy.special.ndtri(numpy.exp(log_p)) fails when log_p < ~-745 due to underflow.

Describe the solution you'd like In the underlying C code for scipy.special.ndtri found here, when p is very small the approximation used for ndtri(p) is an expression in sqrt(-2*log(p)). This formula could then be applied directly to calculate the inverse of the Log CDF of the normal distribution for very small log(p). A function could be written which exponentiates log_p and then uses the existing ndtri implementation on the exponentiated value, except for when log_p is very small, in which case the rational approximation in sqrt(-2*log_p) can be applied directly. Preferably this could be done in C or Cython for performance reasons.

Describe alternatives you've considered

We've already implemented this approach in Python and applied it in our research. A code snippet can be found below. Would there be interest in adding such a solution to scipy through a C extension? If so, I'd be happy to submit a PR, though it may be several weeks before I have the free time to do so. In the mean time, if anyone else has an interest in adding this that would be great too.

import numpy as np from scipy.special import ndtri from numpy.polynomial import Polynomial from scipy._lib._util import _lazywhere _P2 = Polynomial([3.23774891776946035970, 6.91522889068984211695, 3.93881025292474443415, 1.33303460815807542389E0, 2.01485389549179081538e-1, 1.23716634817820021358e-2, 3.01581553508235416007e-4, 2.65806974686737550832e-6, 6.23974539184983293730e-9]) _Q2 = Polynomial([1.00000000000000000000, 6.02427039364742014255, 3.67983563856160859403, 1.37702099489081330271, 2.16236993594496635890e-1, 1.34204006088543189037e-2, 3.28014464682127739104e-4, 2.89247864745380683936e-6, 6.79019408009981274425e-9]) def log_ndtri_small_p(log_p): """Approximation to inverse log CDF normal for log_p


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有